<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改企业环境')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-companyenvironment-edit" th:object="${companyEnvironment}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">企业ID：</label>
                <div class="col-sm-8">
                    <input name="companyId" th:field="*{companyId}" class="form-control" type="text" readonly="readonly" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">环境图片：</label>
<!--                <div class="col-sm-8">-->
<!--                    <input name="imgUrl" th:field="*{imgUrl}" class="form-control" type="text" required>-->
<!--                </div>-->
                <div class="col-sm-8">
                    <div class="layui-upload">
                        <button type="button" class="layui-btn" id="aCoversUpload">上传环境图片</button>
                        <div class="layui-upload-list" id="aCoversShow">
                            <img th:if="${companyEnvironment.imgUrl}" th:src="${companyEnvironment.imgUrl}" style="width: 112px; height: 63px; margin-right: 10px;">
                        </div>
                    </div>
                    <input id="imgUrl" name="imgUrl" class="form-control" type="hidden">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">添加时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="createAt" th:value="${#dates.format(companyEnvironment.createAt, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">
        var prefix = ctx + "jiaqin/companyenvironment";
        $("#form-companyenvironment-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-companyenvironment-edit').serialize());
            }
        }
        layui.use('upload', function(){
            var $ = layui.jquery
                ,upload = layui.upload;

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#aCoversUpload'
                ,url: '/common/upload' //改成您自己的上传接口
                ,before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        $('#aCoversShow').html("");
                        $('#aCoversShow').append('<img src="'+ result +'" alt="'+ file.name +'" style="width: 112px; height: 63px;">')
                    });
                }
                ,done: function(res){
                    //如果上传失败
                    if(res.code > 0){
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    console.log(res);
                    $("#imgUrl").val(res.realPath);
                }
                ,error: function(){
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function(){
                        uploadInst.upload();
                    });
                }
            });
        });
        $("input[name='createAt']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>
